#include "mainwindow.h"
#include "ui_mainwindow.h"

/******************************************************************************
 *
 * @file       mainwindow.cpp
 * @brief      MainWindow
 *
 * @author     Alang
 * @date       2024/10/23
 * @history
 *****************************************************************************/
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowIcon(QIcon(":/images/wechaticon.png"));//生成窗口图标

//    login_dialog = new Login_Dialog(this);//副窗口  主窗口退出时自动回收
//    //将副窗口内嵌入主窗口中
//    login_dialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);

//    setCentralWidget(login_dialog);
//    login_dialog->show();

    chat_dialog = new Chat_Dialog(this);//副窗口  主窗口退出时自动回收
    //将副窗口内嵌入主窗口中
    chat_dialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);

    setCentralWidget(chat_dialog);
    chat_dialog->show();
    //连接注册窗口信号
//    connect(login_dialog,&Login_Dialog::switchRegister,this,&MainWindow::SlotSwitchReg);

//    //连接重置密码窗口信号
//    connect(login_dialog,&Login_Dialog::switchResetPass,this,&MainWindow::SlotSwitchResetPass);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::SlotSwitchReg()
{
    register_dialog = new Register_Dialog(this);//副窗口  主窗口退出时自动回收
    //将副窗口内嵌入主窗口中
    register_dialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);

    //连接登录窗口信号
    connect(register_dialog,&Register_Dialog::switchLogin,this,&MainWindow::SlotSwitchLogin);

    //连接注册成功窗口信号
    connect(register_dialog,&Register_Dialog::switchRegSuccess,this,&MainWindow::SlotSwitchRegSuccess);
    setCentralWidget(register_dialog);
    register_dialog->show();
    login_dialog->hide();
}

void MainWindow::SlotSwitchLogin()
{
    login_dialog = new Login_Dialog(this);//副窗口  主窗口退出时自动回收
    //将副窗口内嵌入主窗口中
    login_dialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);

    //连接注册窗口信号
    connect(login_dialog,&Login_Dialog::switchRegister,this,&MainWindow::SlotSwitchReg);

    //连接重置密码窗口信号
    connect(login_dialog,&Login_Dialog::switchResetPass,this,&MainWindow::SlotSwitchResetPass);
    setCentralWidget(login_dialog);
    login_dialog->show();

}

void MainWindow::SlotSwitchRegSuccess()
{
    regsuccess_dialog = new RegSuccess_Dialog(this);
    //将副窗口内嵌入主窗口中
    regsuccess_dialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);

    //连接注册窗口信号
    connect(regsuccess_dialog,&RegSuccess_Dialog::sig_returnLogin,this,&MainWindow::SlotSwitchLogin);
    setCentralWidget(regsuccess_dialog);

    register_dialog->hide();
    regsuccess_dialog->show();
}

void MainWindow::SlotSwitchResetPass()
{
    resetpass_dialog = new ResetPass_Dialog(this);
    //将副窗口内嵌入主窗口中
    resetpass_dialog->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint);

    //连接注册窗口信号
    connect(resetpass_dialog,&ResetPass_Dialog::sig_returnLogin,this,&MainWindow::SlotSwitchLogin);
    setCentralWidget(resetpass_dialog);

    login_dialog->hide();
    resetpass_dialog->show();
}

